package groep3.ssc.main;

import groep3.ssc.skaterViews.OverView;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

public class SkaterFragment extends Fragment
{

    private View rootView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        rootView = inflater.inflate(R.layout.skater_view, container, false);

        LinearLayout mainRightTop = (LinearLayout) rootView.findViewById(R.id.mainRightTop);
        mainRightTop.addView(new OverView(rootView.getContext()));

        setViews(rootView);

        return rootView;
    }

    @Override
    public View getView()
    {
        View view = super.getView();
        setViews(view);
        return view;
    }

    private void setViews(View rootview)
    {
        LinearLayout mainLeftTop = (LinearLayout) rootView.findViewById(R.id.mainLeftTop);
        if (mainLeftTop != null)
        {
            mainLeftTop.removeAllViews();
            if (Main.skaterView1 != null)
            {
                LinearLayout v = (LinearLayout) Main.skaterView1.getParent();
                if (v != null)
                    v.removeAllViews();

                mainLeftTop.addView(Main.skaterView1);
            }
        }

        LinearLayout mainBottom = (LinearLayout) rootView.findViewById(R.id.mainBottom);
        if (mainBottom != null)
        {
            mainBottom.removeAllViews();
            if (Main.skaterView2 != null)
            {
                LinearLayout v = (LinearLayout) Main.skaterView2.getParent();
                if (v != null)
                    v.removeAllViews();

                mainBottom.addView(Main.skaterView2);
            }
        }
    }
}